package org.softmed.rest.admin.httpMethods;

import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import org.softmed.rest.admin.interfaces.PathChangedListener;
import org.softmed.rest.admin.module.ValidationException;
import org.softmed.swing.IconManager;

import restlet.description.convert.RESTResourceDescription;


public class SimpleDeleteConfig extends JPanel implements KeyListener, DocumentListener {

	JLabel label = new JLabel("Delete");
	JTextField delete = new JTextField();
	JButton clear = new JButton(IconManager.remove);
	private RESTResourceDescription description;
	PathChangedListener pathChangedListener;

	public SimpleDeleteConfig() {
		delete.addKeyListener(this);
		delete.getDocument().addDocumentListener(this);
		setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

		setPreferredSize(new Dimension(540, 25));
		setMaximumSize(new Dimension(540, 25));
		setMinimumSize(new Dimension(540, 25));

		label.setPreferredSize(new Dimension(100, 25));
		label.setMaximumSize(new Dimension(100, 25));
		label.setMinimumSize(new Dimension(100, 25));

		clear.setPreferredSize(new Dimension(20, 20));
		clear.setMaximumSize(new Dimension(20, 20));
		clear.setMinimumSize(new Dimension(20, 20));

		delete.setPreferredSize(new Dimension(420, 25));
		delete.setMaximumSize(new Dimension(420, 25));
		delete.setMinimumSize(new Dimension(420, 25));

		add(label);
		add(delete);
		add(clear);
	}

	public void setResourceDescription(
			RESTResourceDescription resourceDescription) {
		this.description = resourceDescription;
//		delete.setText(description.getDeleteHandler());

	}

	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyReleased(KeyEvent arg0) {
//		description.setDeleteHandler(delete.getText());
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub

	} 

	public void validateData()  throws ValidationException{
//		if (delete.getText() == null || delete.getText().length() == 0) {
//			throw new ValidationException("Module Name can't be empty !!! ");
//		}
		
	}

	public void selectionChanged(String name) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void changedUpdate(DocumentEvent e) {
		pathChangedListener.pathChanged(delete.getText());
		
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		pathChangedListener.pathChanged(delete.getText());
		
	}

	@Override
	public void removeUpdate(DocumentEvent e) {
		pathChangedListener.pathChanged(delete.getText());
		
	}

	public PathChangedListener getPathChangedListener() {
		return pathChangedListener;
	}

	public void setPathChangedListener(PathChangedListener pathChangedListener) {
		this.pathChangedListener = pathChangedListener;
	}
}
